﻿using System.Linq;
using Microsoft.EntityFrameworkCore;
using ZSZ.Application.IService;
using ZSZ.Core.Entities;
using ZSZ.DTO;
using ZSZ.EntityFramework;

namespace ZSZ.Application.Service
{
    public class CommunityService : Repository<CommunityEntity>, ICommunityService
    {
        /*
        private CommunityDTO ToDTO(CommunityEntity en)
        {
            CommunityDTO dto = new CommunityDTO();
            dto.bui
        }*/

        public CommunityDTO[] GetByRegionId(long regionId)
        {
            var cities = GetAllDataEntity().AsNoTracking()
                .Where(c => c.RegionId == regionId);
            return cities.Select(c => new CommunityDTO
            {
                BuiltYear = c.BuiltYear,
                CreateDateTime = c.CreateDateTime,
                Id = c.Id,
                Location = c.Location,
                Name = c.Name,
                RegionId = c.RegionId,
                Traffic = c.Traffic
            }).ToArray();
            
        }

        public CommunityService(ZSZDbContext context) : base(context)
        {
        }
    }
}
